/**
 * @file    app_display.c
 * @brief   显示任务
 * @author  Liuwei
 * @version 1.0.1
 * @date    2023-04-24
 * 
 * @copyright Copyright (c) 2023 JBD-Energy Storage Technology Co. LTD
 * 
 * @par 修改日志:
 * <table>
 * <tr><th>Date       <th>Version   <th>Author   <th>Description
 * <tr><td>2023-04-24 <td>1.0.1     <td>Liuwei   <td>首次创建
 * <tr><td>2024-10-25 <td>1.0.2     <td>Liuwei   <td>新增4灯逻辑策略
 * 指示灯映射表 ：
				 4灯   标准6灯   扩展6灯
		LED1 ->  SOC1  -> SOC1   -> SOC6
		LED2 ->  SOC2  -> SOC2   -> SOC5
		LED3 ->  SOC3  -> SOC3   -> SOC4
		LED4 ->  SOC4  -> SOC4   -> SOC3
		LED5 ->   ALM  -> SOC5   -> SOC2
		LED6 ->   --   -> SOC6   -> SOC1
		LED7 ->   --   -> ALM    -> ALM
		LED8 ->   RUN  -> RUN    -> RUN
		LED9 ->   --   -> MOS    -> MOS
		
 * </table>
 */
/* includes ------------------------------------------------------------------*/
#include "FreeRTOS.h"
#include "If_do.h"
#include "task.h"
#include "cfg_prj.h"
#include "var_mng.h"
#include "diagnosis.h"
#include "app_monitor.h"
#include "If_wdg.h"
#include "app_disp.h"
#include "param_mng.h"
/* macro/define --------------------------------------------------------------*/
#define APP_DISP_INIT_DELAY     (500)  /* 开机状态电亮延时 */
#define APP_DISP_TASK_DELAY     (50)    /* 显示任务运行周期 */

#define LED_SOC_N4   (0xA1)
#define LED_SOC_N6   (0xA2)
#define LED_SOC_E6   (0xA3)

/* typedef -------------------------------------------------------------------*/
typedef struct 
{
    do_id_type led_id;
    uint8_t state;  /* 0:关 , 1:开*/
    uint16_t on_dly_set ;    /*!< 打开延时 */
    uint16_t off_dly_set;    /*!< 关闭延时*/
    uint16_t on_dly_cnt;     /*!< 打开计数器 */
    uint16_t off_dly_cnt;    /*!< 关闭计时器 */
}led_disp_type;

typedef enum
{
    LED_SOC_FLS1  , /* 闪1 */
    LED_SOC_FLS2  , /* 闪2 */
    LED_SOC_FLS3  , /* 闪3 */
    LED_SOC_FLS4  , /* 闪4 */
	LED_SOC_OFF   , /* 常灭 */
	LED_SOC_ON    , /* 常亮 */
	
    LED_SOC_FLSM  , 
}led_flash_type;

/**
 * @brief 灯闪延时对应表
 */
typedef struct 
{
    uint8_t fls_sn ;   /* !< 闪烁序号 */
    uint16_t on_dly ;  /* !< 开启延时*/
    uint16_t off_dly ; /* !< 关闭延时*/
}led_fls_map_type;

enum
{
    LED_ID_SOC1 ,
    LED_ID_SOC2 ,
    LED_ID_SOC3 ,
    LED_ID_SOC4 ,
    LED_ID_SOC5 ,
	LED_ID_SOC6 ,
	LED_ID_ALM  ,
	LED_ID_RUN  , 
    LED_ID_MOS  ,

    LED_ID_MAX,
};
/* local functions -----------------------------------------------------------*/
static uint8_t led_disp_get_dsg_alarm(void);
static uint8_t led_disp_get_static_alarm(void);
static uint8_t led_disp_get_chg_alarm(void);

static void led_disp_set_soc_disp(uint8_t soc_num , uint16_t soc , led_flash_type state);
static uint8_t led_soc_disp_open(uint8_t soc_num ,uint8_t run_step);
static uint8_t led_soc_disp_sleep(uint8_t soc_num ,uint8_t run_step);
static void led_disp_alm_run(led_flash_type alm_state , led_flash_type run_state);
static void led_set_output(uint8_t led_num, uint8_t led_id ,uint8_t state);
/* static variables ----------------------------------------------------------*/
static uint16_t led_delay_cnt = 0;
static uint16_t led_sleep_step = 0;
static uint8_t disp_now_state = LED_POW_UP;  /* 当前显示状态 */
static uint8_t start_led_step = 0;

static led_disp_type led_obj[LED_ID_MAX] =
{
    {DO_SOC_LED1 , 0 , 0 ,  0 , 0 , 0} ,
    {DO_SOC_LED2 , 0 , 0 ,  0 , 0 , 0} ,
    {DO_SOC_LED3 , 0 , 0 ,  0 , 0 , 0} ,
    {DO_SOC_LED4 , 0 , 0 ,  0 , 0 , 0} ,
	{DO_SOC_LED5 , 0 , 0 ,  0 , 0 , 0} ,
    {DO_SOC_LED6 , 0 , 0 ,  0 , 0 , 0} ,
	{DO_ALM_LED  , 0 , 0 ,  0 , 0 , 0} ,
	{DO_RUN_LED  , 0 , 0 ,  0 , 0 , 0} , 
    {DO_MOS_LED  , 0 , 0 ,  0 , 0 , 0} ,
};

static do_id_type led_soc4_map[LED_ID_MAX] = 
{
	DO_SOC_LED1 ,
	DO_SOC_LED2 ,
	DO_SOC_LED3 ,
	DO_SOC_LED4 ,
	DO_SOC_LED6 ,  //填充位置，
	DO_ALM_LED  ,
	
	DO_SOC_LED5 ,  // 告警引脚
	DO_RUN_LED  ,
	DO_MOS_LED  ,
};

static do_id_type led_soc6_map[LED_ID_MAX] = 
{
	DO_SOC_LED1 ,
	DO_SOC_LED2 ,
	DO_SOC_LED3 ,
	DO_SOC_LED4 ,
	DO_SOC_LED5 , 
	DO_SOC_LED6 ,
	
	DO_ALM_LED  ,
	DO_RUN_LED  ,
	DO_MOS_LED  ,
};

static do_id_type led_ext6_map[LED_ID_MAX] = 
{
	DO_SOC_LED6 ,
	DO_SOC_LED5 ,
	DO_SOC_LED4 ,
	DO_SOC_LED3 ,
	DO_SOC_LED2 ,  //填充位置，
	DO_SOC_LED1 ,
	
	DO_ALM_LED  ,
	DO_RUN_LED  ,
	DO_MOS_LED  ,
};

/**
 * @brief 灯闪延时映射表
 */
static const led_fls_map_type led_fls_dly_map[LED_SOC_FLSM] =
{
    /* @attention 延时单位 ms*/
    {LED_SOC_FLS1 , 250 , 3750  } , /* 闪1 */
    {LED_SOC_FLS2 , 500 , 500   } , /* 闪2 */
    {LED_SOC_FLS3 , 500 , 1500  } , /* 闪3 */
    {LED_SOC_FLS4 , 350 , 300   } , /* 闪4 */
    {LED_SOC_OFF  , 0x0 , 0xffff} , /* 常灭 */
	{LED_SOC_ON   , 0xffff , 0  } , /* 常亮 */
};

/* global variables ----------------------------------------------------------*/

/** ------------------------------------------------------------------------- *
  *                             Global function
 ** ------------------------------------------------------------------------- */
/**
 * @brief  APP层显示任务
 * @param  pvParameters
 */
void vAppDispTasks(void *pvParameters)
{
    uint8_t i = 0;
	uint8_t sys_state = 0;
	uint16_t disp_soc = 0;
	uint32_t task_cycle = 0;
	uint8_t led_soc_num = 0;
	uint8_t mos_led_run = 0;
	uint16_t func_cfg = 0;
	
    portTickType xLastExecutionTime;
	
    xLastExecutionTime = xTaskGetTickCount();
	
	task_run_reset(TASK_ID_DISP);
	
	for( i = 0;i < LED_ID_MAX; ++ i)
    {
         If_do_set_output(led_obj[i].led_id , DO_OUT_OFF);
    }

    for( ;; )
    {
		task_cycle = task_get_cycle(TASK_ID_DISP);
		if(task_cycle >= APP_DISP_TASK_DELAY * 8)
			task_cycle = APP_DISP_TASK_DELAY;
		
		param_get_2bits_val(PAR_ID_FUNC_CFG ,FUNC_NSOC_POS , &func_cfg); 
		if(PARAM_FUNC_CFG_EN == func_cfg)
		{
			led_soc_num = LED_SOC_N4;
		}
		else
		{
			param_get_2bits_val(PAR_ID_FUNC_CFG ,FUNC_RSOC_POS , &func_cfg); 
			if(PARAM_FUNC_CFG_EN == func_cfg)
			{
				led_soc_num = LED_SOC_E6;
			}
			else
			{
				led_soc_num = LED_SOC_N6;
			}
		}
		
        switch(disp_now_state)
        {
            case LED_POW_UP:
				led_delay_cnt += task_cycle;
                if(led_delay_cnt >= APP_DISP_INIT_DELAY)
                {	
					led_delay_cnt = 0;
					if(start_led_step % 2)
					{
						If_do_set_output(DO_SYS_RLED , DO_OUT_ON);
					}
					else
					{
						If_do_set_output(DO_SYS_RLED , DO_OUT_OFF);
					}
					
					if(TRUE == led_soc_disp_open(led_soc_num , start_led_step))
					{
						disp_now_state = LED_RUN_STATE ;
						start_led_step = 0;
					}
					else
					{
						++ start_led_step;
					}
				}
                break; 
			case LED_RUN_STATE:
				if(TOOL_MODE_DEBUG != var_get_data(VAR_ID_TOOL_MODE)) // 非工装模式
				{
					sys_state = var_get_data(VAR_ID_CURR_DR);
					disp_soc = var_get_data(VAR_ID_DISP_SOC) * 0.1;
				param_get_2bits_val(PAR_ID_FUNC_CFG ,FUNC_MOSLED_POS , &func_cfg); 
				if(PARAM_FUNC_CFG_EN == func_cfg)
				  {
						if(diag_get_prp(PRP_ID_FT_DMOS)||diag_get_prp(PRP_ID_FT_AFE)||
							diag_get_prp(PRP_ID_FT_CMOS)||diag_get_prp(PRP_ID_COL)||diag_get_prp(PRP_ID_TOL))
						{
							led_obj[LED_ID_MOS].on_dly_set = led_fls_dly_map[LED_SOC_OFF].on_dly;
							led_obj[LED_ID_MOS].off_dly_set = led_fls_dly_map[LED_SOC_OFF].off_dly;
						}
						else
						{
							led_obj[LED_ID_MOS].on_dly_set = led_fls_dly_map[LED_SOC_ON].on_dly;
							led_obj[LED_ID_MOS].off_dly_set = led_fls_dly_map[LED_SOC_ON].off_dly;
						}
				  }
				  else 
				  {
						if(diag_get_prp(PRP_ID_FT_DMOS)||diag_get_prp(PRP_ID_FT_AFE)||
							diag_get_prp(PRP_ID_FT_CMOS)||diag_get_prp(PRP_ID_COL)||diag_get_prp(PRP_ID_TOL))
						{
							led_obj[LED_ID_MOS].on_dly_set = led_fls_dly_map[LED_SOC_ON].on_dly;
							led_obj[LED_ID_MOS].off_dly_set = led_fls_dly_map[LED_SOC_ON].off_dly;
						}
						else
						{
							led_obj[LED_ID_MOS].on_dly_set = led_fls_dly_map[LED_SOC_OFF].on_dly;
							led_obj[LED_ID_MOS].off_dly_set = led_fls_dly_map[LED_SOC_OFF].off_dly;
						}
				  }					
					/* 过流 、过温、短路等失效性保护 */
					if(diag_get_prp(PRP_ID_OCC)||diag_get_prp(PRP_ID_OCC2)||diag_get_prp(PRP_ID_OCD)
						||diag_get_prp(PRP_ID_OCD2)||diag_get_prp(PRP_ID_OTC)||diag_get_prp(PRP_ID_UTC)
						||diag_get_prp(PRP_ID_OTD)||diag_get_prp(PRP_ID_UTD)||diag_get_prp(PRP_ID_OTM)
						||diag_get_prp(PRP_ID_OTE)||diag_get_prp(PRP_ID_UTE)||diag_get_prp(PRP_ID_FT_CMOS)
						||diag_get_prp(PRP_ID_FT_DMOS)||diag_get_prp(PRP_ID_FT_AFE)||diag_get_prp(PRP_ID_SC)
						||diag_get_prp(PRP_ID_COL)||diag_get_prp(PRP_ID_TOL))
					{
						led_disp_set_soc_disp(led_soc_num ,0 ,LED_SOC_OFF);
						led_disp_alm_run(LED_SOC_ON , LED_SOC_OFF);
					}
					/* 过压保护 */
					else if(diag_get_prp(PRP_ID_COV) || diag_get_prp(PRP_ID_BOV))
					{
						led_disp_set_soc_disp(led_soc_num ,disp_soc ,LED_SOC_ON);
						led_disp_alm_run(LED_SOC_OFF , LED_SOC_ON);					
					}
					/* 欠压保护 */
					else if(diag_get_prp(PRP_ID_CUV) || diag_get_prp(PRP_ID_BUV))
					{
						led_disp_set_soc_disp(led_soc_num , 0 ,LED_SOC_OFF);
						led_disp_alm_run(LED_SOC_OFF , LED_SOC_OFF);		
					}
					else
					{
						sys_state = var_get_data(VAR_ID_CURR_DR);
						if(CURR_DR_CHG == sys_state)
						{
                            if(disp_soc == 0)
								disp_soc += 1;  //LL 解决SOC充电是为0 不闪烁问题 - 补丁							
							led_disp_set_soc_disp(led_soc_num , disp_soc ,LED_SOC_FLS2);	
							if(TRUE == led_disp_get_chg_alarm())
								led_disp_alm_run(LED_SOC_FLS3 , LED_SOC_ON);
							else
								led_disp_alm_run(LED_SOC_OFF , LED_SOC_ON);								
						}
						else if(CURR_DR_DSG == sys_state)
						{
							led_disp_set_soc_disp(led_soc_num ,disp_soc ,LED_SOC_ON);
							if(TRUE == led_disp_get_dsg_alarm())
								led_disp_alm_run(LED_SOC_FLS3 , LED_SOC_FLS3);
							else
								led_disp_alm_run(LED_SOC_OFF , LED_SOC_FLS3);
						}
						else
						{
							led_disp_set_soc_disp(led_soc_num ,disp_soc ,LED_SOC_ON);
							if(TRUE == led_disp_get_static_alarm())
								led_disp_alm_run(LED_SOC_FLS3 , LED_SOC_FLS1);
							else
								led_disp_alm_run(LED_SOC_OFF , LED_SOC_FLS1);
						}
					}
					
					/* 执行点亮动作 */
					for( i = 0; i < LED_ID_MAX ; ++ i)
					{
						if(led_obj[i].state)
						{
							if(led_obj[i].off_dly_set == 0xffff)
							{
								led_set_output(led_soc_num , i , DO_OUT_OFF);
								led_obj[i].off_dly_cnt = 0;
								led_obj[i].on_dly_cnt = 0;
							}
							else
							{
								led_obj[i].off_dly_cnt += task_cycle;
								if(led_obj[i].off_dly_cnt >= led_obj[i].off_dly_set)
								{
									led_obj[i].off_dly_cnt = 0;
									led_obj[i].state = 0;
									led_set_output(led_soc_num , i , DO_OUT_ON);
								}
							}
						}
						else
						{
							if(led_obj[i].on_dly_set == 0xffff)
							{
								led_obj[i].off_dly_cnt = 0;
								led_obj[i].on_dly_cnt = 0;
								led_set_output(led_soc_num , i , DO_OUT_ON);
							}
							else
							{
								led_obj[i].on_dly_cnt += task_cycle;
								if(led_obj[i].on_dly_cnt >= led_obj[i].on_dly_set)
								{
									led_obj[i].on_dly_cnt = 0;
									led_obj[i].state = 1;
									led_set_output(led_soc_num , i , DO_OUT_OFF);
									
								}
							}
						}
					}
					
					led_delay_cnt += task_cycle;
					if(led_delay_cnt >= APP_DISP_INIT_DELAY)
					{	
						led_delay_cnt = 0;
						start_led_step ++;
						if(start_led_step % 2)
						{
							If_do_set_output(DO_SYS_RLED , DO_OUT_ON);
						}
						else
						{
							If_do_set_output(DO_SYS_RLED , DO_OUT_OFF);
						}
					}
				}
				else
				{
					for( i = 0;i < LED_ID_MAX; ++ i)
					{
						if(var_get_data(VAR_ID_LED_SW) & (1 << i))
							If_do_set_output(led_obj[i].led_id , DO_OUT_ON);
						else
							If_do_set_output(led_obj[i].led_id , DO_OUT_OFF);
					}
				}
				led_sleep_step = 0;
				break;
            case LED_SLEEP_STATE:
				led_delay_cnt += task_cycle;
				if(led_delay_cnt >= APP_DISP_INIT_DELAY)
				{	
					led_delay_cnt = 0;
					if(FALSE == led_soc_disp_sleep(led_soc_num , led_sleep_step))
						++ led_sleep_step;
					else
						disp_now_state = LED_SLEEP_CMP;
				}
                break;
			case LED_SLEEP_CMP:
				break;
            default:
                disp_now_state = LED_RUN_STATE;
                break;
        }
		
		task_run_count(TASK_ID_DISP);
        
		vTaskDelayUntil( &xLastExecutionTime , APP_DISP_TASK_DELAY);
	}
}

void led_disp_set_state(uint8_t run_state)
{
	if(disp_now_state < LED_STATE_MAX)
	{
		disp_now_state = run_state;
	}
}

uint8_t led_disp_get_state(void)
{
	return disp_now_state;
}
/** ------------------------------------------------------------------------- *
  *                              Local function
 ** ------------------------------------------------------------------------- */
static void led_disp_set_soc_disp(uint8_t led_num , uint16_t soc , led_flash_type state)
{
    uint8_t i = 0;
    uint8_t disp_idx = 0;
	uint8_t soc_num = 0;
	
	if(LED_SOC_N4 == led_num)
	{
		disp_idx = soc / 250;
		if(((soc % 250) == 0) && (soc >= 250))
			disp_idx -= 1;
		
		soc_num = 4;
		
		led_obj[LED_ID_SOC5].on_dly_set = 0; 
		led_obj[LED_ID_SOC5].off_dly_set = 0xffff;
		
		led_obj[LED_ID_SOC6].on_dly_set = 0; 
		led_obj[LED_ID_SOC6].off_dly_set = 0xffff;
	}
	else
	{
		disp_idx = soc / 166;
		if(((disp_idx % 166) == 0) && (disp_idx >= 166))
		   disp_idx -= 1;
		
		soc_num = 6;
	}
	
	if(soc == 0)
    {
        for( i = 0;i < soc_num; ++ i)
        {
            led_obj[i].on_dly_set = 0;
            led_obj[i].off_dly_set = 0xffff;
        }

        return ;
    }
	
	for( i = 0;(disp_idx > 0) && (i < disp_idx); ++ i)
    {
        led_obj[i].on_dly_set = 0xffff;
        led_obj[i].off_dly_set = 0;
    }
	
    if(state >= LED_SOC_FLSM)
        state = LED_SOC_OFF;

    led_obj[disp_idx].on_dly_set = led_fls_dly_map[state].on_dly; 
    led_obj[disp_idx].off_dly_set = led_fls_dly_map[state].off_dly;
       
    for(i = disp_idx + 1; i < soc_num; ++ i)
    {
        led_obj[i].on_dly_set = 0;
        led_obj[i].off_dly_set = 0xffff;
    }
}

static void led_disp_alm_run(led_flash_type alm_state , led_flash_type run_state)
{
	if((alm_state >= LED_SOC_FLSM) || (run_state >= LED_SOC_FLSM))
		return ;
	
    led_obj[LED_ID_ALM].on_dly_set = led_fls_dly_map[alm_state].on_dly; 
    led_obj[LED_ID_ALM].off_dly_set = led_fls_dly_map[alm_state].off_dly; 
    
	led_obj[LED_ID_RUN].on_dly_set = led_fls_dly_map[run_state].on_dly; 
    led_obj[LED_ID_RUN].off_dly_set = led_fls_dly_map[run_state].off_dly; 
}

static uint8_t led_disp_get_chg_alarm(void)
{
	if(diag_get_alarm(ALM_ID_OCC) || diag_get_alarm(ALM_ID_UTC) || diag_get_alarm(ALM_ID_OTC)
	 ||diag_get_alarm(ALM_ID_OTM) || diag_get_alarm(ALM_ID_UTE) || diag_get_alarm(ALM_ID_OTE)
	 ||diag_get_alarm(ALM_ID_VDIFF))
	{
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}

static uint8_t led_disp_get_dsg_alarm(void)
{
	if(diag_get_alarm(ALM_ID_OCD) || diag_get_alarm(ALM_ID_UTD) || diag_get_alarm(ALM_ID_OTD)
	 ||diag_get_alarm(ALM_ID_OTM) || diag_get_alarm(ALM_ID_UTE) || diag_get_alarm(ALM_ID_OTE)
	 ||diag_get_alarm(ALM_ID_VDIFF))
	{
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}

static uint8_t led_disp_get_static_alarm(void)
{
	if(diag_get_alarm(ALM_ID_OCD) || diag_get_alarm(ALM_ID_UTD) || diag_get_alarm(ALM_ID_OTD)
	   ||diag_get_alarm(ALM_ID_OCC) || diag_get_alarm(ALM_ID_UTC) || diag_get_alarm(ALM_ID_OTC)
	   ||diag_get_alarm(ALM_ID_OTM) || diag_get_alarm(ALM_ID_UTE) || diag_get_alarm(ALM_ID_OTE)
	   ||diag_get_alarm(ALM_ID_VDIFF))
	{
		return TRUE;
	}
	else
	{
		return FALSE;
	}
}

static uint8_t led_soc_disp_open(uint8_t soc_num ,uint8_t run_step)
{
	if(LED_SOC_N4 == soc_num)  // 4灯 SOC开机显示
	{
		if(run_step == 0)
		{
			If_do_set_output(led_soc4_map[LED_ID_SOC1] , DO_OUT_ON);
		}
		else if(run_step < 4)
		{
			If_do_set_output(led_soc4_map[run_step - 1] , DO_OUT_OFF);
			If_do_set_output(led_soc4_map[run_step] , DO_OUT_ON);			
		}
		else if(run_step == 4)
		{
			If_do_set_output(led_soc4_map[LED_ID_SOC4] , DO_OUT_OFF);
			If_do_set_output(led_soc4_map[LED_ID_ALM] , DO_OUT_ON);	
		}
		else if(run_step == 5)
		{
			If_do_set_output(led_soc4_map[LED_ID_ALM] , DO_OUT_OFF);
			If_do_set_output(led_soc4_map[LED_ID_RUN] , DO_OUT_ON);		
		}
		else
		{
			return TRUE;
		}
		
		return FALSE;
	}
	else if(LED_SOC_E6 == soc_num)  // 扩展6灯开机显示
	{
		if(run_step == 0)
		{
			If_do_set_output(led_ext6_map[LED_ID_SOC1] , DO_OUT_ON);
		}
		else if(run_step < LED_ID_MAX)
		{
			If_do_set_output(led_ext6_map[run_step - 1] , DO_OUT_OFF);
			If_do_set_output(led_ext6_map[run_step] , DO_OUT_ON);			
		}
		else
		{
			return TRUE;
		}
		
		return FALSE;		
	}
	else   // 标准6灯开机显示
	{
		if(run_step == 0)
		{
			If_do_set_output(led_soc6_map[LED_ID_SOC1] , DO_OUT_ON);
		}
		else if(run_step < LED_ID_MAX)
		{
			If_do_set_output(led_soc6_map[run_step - 1] , DO_OUT_OFF);
			If_do_set_output(led_soc6_map[run_step] , DO_OUT_ON);			
		}
		else
		{
			return TRUE;
		}
		
		return FALSE;
	}
}

static uint8_t led_soc_disp_sleep(uint8_t led_num ,uint8_t run_step)
{
	uint8_t i = 0;
	
	if(LED_SOC_N4 == led_num)
	{
		if(run_step == 0)
		{
			for(i = 0;i < LED_ID_MAX; ++ i)
			{
				If_do_set_output(led_soc4_map[i] , DO_OUT_ON);
			}
		}
		else if(run_step == 1)
		{
			If_do_set_output(led_soc4_map[LED_ID_RUN] , DO_OUT_OFF);		
		}
		else if(run_step == 2)
		{
			If_do_set_output(led_soc4_map[LED_ID_ALM] , DO_OUT_OFF);		
		}
		else if(run_step <= LED_ID_MAX)
		{
			If_do_set_output(led_soc4_map[LED_ID_SOC4 + 3 - run_step] , DO_OUT_OFF);		
		}
		else
		{
			return TRUE;
		}
		return FALSE;
	}
	else if(LED_SOC_E6 == led_num)
	{
		if(run_step == 0)
		{
			for(i = 0;i < LED_ID_MAX; ++ i)
			{
				If_do_set_output(led_ext6_map[i] , DO_OUT_ON);
			}
		}
		else if(run_step <= LED_ID_MAX)
		{
			If_do_set_output(led_ext6_map[LED_ID_MAX - run_step] , DO_OUT_OFF);		
		}
		else
		{
			return TRUE;
		}
		return FALSE;
	}
	else 
	{
		if(run_step == 0)
		{
			for(i = 0;i < LED_ID_MAX; ++ i)
			{
				If_do_set_output(led_soc6_map[i] , DO_OUT_ON);
			}
		}
		else if(run_step <= LED_ID_MAX)
		{
			If_do_set_output(led_soc6_map[LED_ID_MAX - run_step] , DO_OUT_OFF);		
		}
		else
		{
			return TRUE;
		}
		
		return FALSE;
	}
}

static void led_set_output(uint8_t led_num, uint8_t led_id ,uint8_t state)
{
	if(led_id >= LED_ID_MAX)
		return ;
	
	if(LED_SOC_N4 == led_num)
	{
		If_do_set_output(led_soc4_map[led_id] , state);
	}
	else if(LED_SOC_E6 == led_num)
	{
		If_do_set_output(led_ext6_map[led_id] , state);
	}
	else
	{
		If_do_set_output(led_soc6_map[led_id] , state);
	}
}

/********** Copyright (c) 2024 JBD-Energy Storage Technology Co. LTD *********/


